package ru.pb.game.network.engine.client.packets.receivable;

import ru.pb.game.network.engine.client.packets.FromClientToGameServerPacket;
import ru.pb.game.objects.model.players.Player;
import ru.pb.game.objects.model.players.enums.SLOT_STATE;
import ru.pb.game.objects.model.room.Room;

public class PROTOCOL_ROOM_CLOSE_SLOT_REQ extends FromClientToGameServerPacket
{
	private int _slot;

	@Override
	public void readImpl()
	{
		readH();
		_slot = readC();
		readC();
		readC();
		readC();
	}

	@Override
	public void runImpl()
	{
		Player p = getPlayer();
		if(p != null)
		{
			Room r = p.getRoom();
			if(r != null)
			{
				switch(r.getSlotState(_slot))
				{
					case SLOT_STATE_EMPTY:
					{
						r.changeSlotState(_slot, SLOT_STATE.SLOT_STATE_CLOSE);
						break;
					}
					case SLOT_STATE_CLOSE:
					{
						r.changeSlotState(_slot, SLOT_STATE.SLOT_STATE_EMPTY);
						break;
					}
				}
			}
		}
	}
}
